package hot100;

import java.util.LinkedList;
import java.util.List;

public class Solution590 {
    List<Integer> ans = new LinkedList<>();
    public List<Integer> postorder(Node root) {
        dfs(root);
        return ans;
    }

    private void dfs(Node root) {
        if (root == null) {
            return;
        }
        if (root.children != null && root.children.size() > 0) {
            root.children.forEach(this::dfs);
        }
        ans.add(root.val);
    }
}

class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
